package com.dfd.mango.admin.security;

import com.dfd.mango.admin.util.SecurityUtils;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.web.authentication.www.BasicAuthenticationFilter;

import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/*
 *文件名: JwtAuthenticationFilter
 *创建者: 东东
 *创建时间:2021/8/18 15:42
 *描述:   登录认证过滤器
 *  负责登录认证时检查并生产令牌保存到上下文
 *
 */
public class JwtAuthenticationFilter extends BasicAuthenticationFilter {
    public JwtAuthenticationFilter(AuthenticationManager authenticationManager) {
        super(authenticationManager);
    }

    @Override
    protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain) throws IOException, ServletException {
        // 获取token并检查登录状态
        SecurityUtils.checkAuthentication(request);
        chain.doFilter(request,response);
    }
}
